import request from "./index";
import qs from "qs";

export function get(url, params = {}) {
  return request.get(url, params);
}

export function post(url, data = {}) {
  // 使用默认 application/json 形式的post请求
  return request.post(url, data);
}

export function post_urlencoded(url, data, headers = null) {
  // 使用 application/x-www-urlencoded 形式的post请求
  return request.post(url, qs.stringify({ data: JSON.stringify(data) }), {
    headers,
  });
}

export function post_formData(url, data) {
  // 使用 formData 形式的post请求
  let formData = new FormData();
  Object.getOwnPropertyNames(data).forEach((key) => {
    formData.append(key, data[key]);
  });
  return request.post(url, formData, {
    headers: {
      "Content-Type":
        "multipart/form-data; boundary=----WebKitFormBoundary{???}", // 需要设置正确的FormBoundary
    },
  });
}
